package org.jeecg.modules.parameter.biz.controlltr;


import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.system.base.controller.JeecgController;
import org.jeecg.modules.parameter.api.dto.exit.SimExitDto;
import org.jeecg.modules.parameter.api.entity.SimExit;
import org.jeecg.modules.parameter.api.entity.SimLine;
import org.jeecg.modules.parameter.api.entity.power.SimPower;
import org.jeecg.modules.parameter.api.vo.exit.SimExitVo;
import org.jeecg.modules.parameter.api.vo.power.SimPowerJsonVo;
import org.jeecg.modules.parameter.biz.service.SimLineService;
import org.jeecg.modules.parameter.biz.service.SimStationExitService;
import org.jeecg.modules.parameter.common.api.dto.PatchPO;
import org.jeecg.modules.parameter.common.utils.oConvertUtils;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author lsy
 * @date 2024/09/17
 */
@Api(tags = "参数管理-车站-出入口管理")
@RestController
@RequestMapping(value = {"/stationExitInfo"}, produces = {"application/json; charset=utf-8"})
@Slf4j
public class SimStationExitController extends JeecgController<SimExit, SimStationExitService> {
    @Resource
    private SimStationExitService simStationExitService;

    @ApiOperation(value = "按车站ID查询出入口信息", notes = "查询车站的出入口信息")
    @PostMapping(value = "/getExitBySataId")
    public Result<List<SimExitVo>> getExitBySataId(@RequestParam(name = "stationId", required = true) String id) {
        List<SimExitVo> simExitVo = oConvertUtils.entityListToModelList(simStationExitService.getExitBySataId(id), SimExitVo.class);
        return Result.ok(simExitVo);
    }

    @ApiOperation(value = "按ID删除车站出入口", notes = "按ID删除车站出入口")
    @DeleteMapping(value = "/delExit")
    public Result<String> delExit(@RequestParam(name = "exitId", required = true) String id) {
        simStationExitService.removeById(id);
        return Result.ok("删除成功");
    }

    @ApiOperation(value = "按ID查询车站出入口", notes = "按ID查询车站出入口")
    @PostMapping(value = "/queryExitById")
    public Result<SimExitVo> queryExitById(@RequestParam(name = "exitId", required = true) String id) {
        return Result.ok(oConvertUtils.entityToModel(simStationExitService.getById(id), SimExitVo.class));
    }


    @ApiOperation(value = "添加车站出入口信息", notes = "添加车站出入口信息")
    @PostMapping(value = "/addExit")
    public Result<String> addExit(@RequestBody  SimExitDto simExitDto) {
        simStationExitService.save(oConvertUtils.entityToModel(simExitDto, SimExit.class));
        return Result.ok("保存成功");
    }


    @ApiOperation(value = "修改车站出入口信息", notes = "修改车站出入口信息")
    @PutMapping(value = "/updateExit")
    public Result<String> updateExit(@RequestBody PatchPO patchPO) {
        simStationExitService.updatePatch(patchPO);
        return Result.OK("更新成功!");
    }
}
